<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
//商品表
use Common\Model\Shop;
//类型属性表
use Common\Model\Attribute;
//分类表
use Common\Model\Category;
//品牌表
use Common\Model\Brand;
//商品属性表
use Common\Model\Shop_attribute;
//商品详细表
use Common\Model\Shop_detailed;
class IndexController extends Controller{
	private $model;
	//构造函数
	public function __init(){
		$this->model = new Category;
	}	    
	
//	首页
    public function index(){
//  	分配分类
    	$cateData=$this->model->where("pid=0")->get();
//		p($cateData);
		View::with('cateData',$cateData);
////		获得价格id
//		$jcid=$this->model->where("cname='价格'")->pluck('cid');
//		p($jcid);
//		$cateDataJiage=$this->model->where("pid={$jcid}")->get();
//		获得级别id	
		$cid=$this->model->where("cname='级别'")->pluck('cid');
		$cateDataJibie=$this->model->where("pid={$cid}")->get();
/** 
 * 二维数组根据某个字段排序 
 * 功能：按照用户的年龄倒序排序 
 * @author ruxing.li 
 */ 
//		$sort = array(  
//      'direction' => 'SORT_ASC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
//      'field'     => 'cid',       //排序字段  
//		);  
//		$arrSort = array();  
//		foreach($cateDataJiage AS $key => $value){  
//		    foreach($value AS $k=>$v){  
//		        $arrSort[$k][$key] = $v;  
//		    }  
//		}  
//		if($sort['direction']){  
//		    array_multisort($arrSort[$sort['field']], constant($sort['direction']), $cateDataJiage);  
//		}  
		  
//		var_dump($cateDataJiage);exit;
//		p($cateDataJiage);exit;
//		$jiage=$cateDataSon
		View::with('cateDataJibie',$cateDataJibie);
//		View::with('cateDataJiage',$cateDataJiage);
//		分配品牌
		$brandModel=new Brand;
		$brandData=$brandModel->limit('7')->get();
		View::with('brandData',$brandData);
//		根据用户所选品牌获得分类id
		$shopModel=new Shop;


//		p($brandData);exit;
		$brandDataA=$brandModel->where("sort='A'")->get();
		$brandDataB=$brandModel->where("sort='B'")->get();
		View::with('brandDataA',$brandDataA);
		View::with('brandDataB',$brandDataB);		
//		p($brandData);exit;
//		分配商品

		$shopData=$shopModel->limit(8)->get();
		$sort = array(  
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'sid',       //排序字段  
		);  
		$arrSort = array();  
		foreach($shopData AS $key => $value){  
		    foreach($value AS $k=>$v){  
		        $arrSort[$k][$key] = $v;  
		    }  
		}  
		if($sort['direction']){  
		    array_multisort($arrSort[$sort['field']], constant($sort['direction']), $shopData);  
		}  
		View::with('shopData',$shopData);
//		p($shopData);exit;
       	View::make();
    }
}
